package com.code516.dao;

import com.code516.entity.WorkEntity;
import com.code516.entity.pojo.WorkStudentPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface WorkDao {

    @Insert(value = "insert into works_info(workName,workUrl,coverUrl,workType,releaseTime,workInfo,opeartInfo,stuId,isUsed) values(#{workEntity.workName},#{workEntity.workUrl},#{workEntity.coverUrl},#{workEntity.workType},#{workEntity.releaseTime},#{workEntity.workInfo},#{workEntity.opeartInfo},#{workEntity.stuId},#{workEntity.isUsed})")
    public int saveWorkEntity(@Param("workEntity") WorkEntity workEntity) throws Exception;

    @Select(value = "select * from works_info wi, stu_info si where si.stuId=wi.stuId ")
    public List<WorkStudentPojo> findAll() throws Exception;

    @Select(value = "select * from works_info wi, stu_info si where si.stuId=wi.stuId and wi.workId=#{workId}")
    public WorkStudentPojo findById(int workId) throws Exception;

    @Select(value = "select * from works_info where workUrl=#{workUrl}")
    public WorkEntity findByWorkUrl(String workUrl) throws Exception;

    @Select(value = "select * from works_info wi, stu_info si where si.stuId=wi.stuId and wi.stuId=#{stuId} ")
    public List<WorkStudentPojo> findByStuId(int stuId) throws Exception;

    @Select(value = "select count(*) from works_info wi, stu_info si where si.stuId=wi.stuId and wi.stuId=#{stuId} ")
    public int findTotal(int stuId) throws Exception;

}
